home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / utilities / pu062.dms / pu062.adf / AutoPics / autopics2.c < prev    next >
C/C++ Source or Header  |  1987-08-08  |  3KB  |  120 lines

  1. /* AUTOPICS  by  Nick Ruppert  5-23-87
  2.     will call your viewing program to display all the pics in a directory
  3.     having the user-specified extension (such as .pic or .ham).
  4.     Autopics will default to "uShow" and ".pic".
  5.     Compiled with Manx Aztec 3.4 +l.  Linked with c32.lib.
  6. */
  7. /*
  8.     For questions & comments, I can be reached thru
  9.     PSA BBS (sysop Dorothy Dean)
  10.     414-278-5390
  11. */
  12. #include <stdio.h>
  13. main(argc, argv)
  14. int argc;
  15. char *argv[];
  16. {
  17.     static char extension[7];  /* storage for extension (* + 5 chars + EOS)*/
  18.     static char *args[] = {"uShow", ".pic", ""};
  19.     static char *defaults[] = {"Defaulting to \"uShow\" and \".pic\".",
  20.                 "Defaulting to \"uShow\".", "Defaulting to \".pic\"."};
  21.     char *scdir(), *malloc(), *ptr, *files[100], *usage = 
  22.         "USAGE: autopics [viewing_prog] [extension] [start (optional)]";
  23.         /* ptr = pointer to temp dir filename */
  24.     int count, count1, compare();
  25.  
  26.     switch (argc)
  27.     {
  28.     case (1) :    puts(usage); puts(defaults[0]); break;
  29.     case (2) :    if (argv[1][0] == '.')
  30.                     { args[1] = argv[1]; puts(defaults[1]); }
  31.                 else if (tolower(argv[1][0]) == 's' && argv[1][1] == '=')
  32.                     { args[2] = &argv[1][2]; puts(defaults[0]); }
  33.                 else
  34.                     { args[0] = argv[1]; puts(defaults[2]); }
  35.                 break;
  36.     case (3) :  if (tolower(argv[2][0]) == 's' && argv[2][1] == '=')
  37.                     args[2] = &argv[2][2];
  38.                 else
  39.                     { args[0] = argv[1]; args[1] = argv[2]; break; }
  40.                 if (argv[1][0] == '.')
  41.                     { args[1] = argv[1]; puts(defaults[1]); }
  42.                 else
  43.                     { args[0] = argv[1]; puts(defaults[2]); }
  44.                 break;
  45.     case (4) :    for (count = 1; count < argc-1; count++)
  46.                     args[count-1] = argv[count];
  47.                 if (tolower(argv[count][0]) == 's' && argv[count][1] == '=')
  48.                     args[count-1] = &argv[count][2];
  49.                 break;
  50.     default :    puts("Too many args."); 
  51.                 puts(usage);
  52.                 exit();
  53.     }
  54.     extension[0] = '*';  /* make 1st extension char '*' */
  55.     for (count = 0; count < strlen(args[1]) && count < 5; count++)
  56.         extension[count+1] = args[1][count];
  57.     fputs("Reading the directory for all files", stdout);
  58.     fputs(" with the extension \"", stdout);
  59.     fputs(extension, stdout);
  60.     puts("\"...");
  61.     for (count = 0; (ptr = scdir(extension)) && count < 100; count++)
  62.         {
  63.         files[count] = malloc(strlen(ptr)+1);
  64.         strcpy(files[count], ptr);
  65.         }
  66.     if (count)
  67.         {
  68.         count1 = 0; /* initialize */
  69.         if (*args[2])
  70.             {
  71.             for (; compare(args[2], files[count1]) &&
  72.                 count1 < count; count1++) ;
  73.             if (count1 == count)
  74.                 {
  75.                 fputs("\nERROR: \"", stdout);
  76.                 fputs(args[2], stdout);
  77.                 puts("\" is not in this directory");
  78.                 exit(1);
  79.                 }
  80.             }
  81.         puts("\nNow viewing...");
  82.         for (; count1 < count; count1++)
  83.             {
  84.             puts(files[count1]); 
  85.             if (fexecl(args[0], 0L, files[count1], 0L) != 0) 
  86.                 {
  87.                 fputs("\nERROR: I am unable to use ",stdout);
  88.                 fputs(args[0], stdout);
  89.                 fputs(" to show ", stdout);
  90.                 puts(files[count1]);
  91.                 exit(1);
  92.                 }
  93.             }
  94.         puts("END OF PICTURES\n");
  95.         }
  96.     else 
  97.         {
  98.         fputs("\nSorry, there are no files with the extension ", stdout);
  99.         puts(&extension[1]);
  100.         }
  101. }
  102.  
  103.  /*     -     -     -     -     -     -     -     -     -     -     -     */
  104.  
  105. /* compare 2 strings regardless of case returning 0 if a match */
  106. int compare(s1, s2)
  107. char *s1, *s2;
  108. {
  109.     for (; *s1 != '\0'; s1++, s2++)
  110.         {
  111.         if (*s1 == '#' && *(s1+1) == '?') /* match all */
  112.             return (0);
  113.         if (*s1 == '?') /* wildcard */
  114.             continue;
  115.         if(toupper(*s1) != toupper(*s2))
  116.             return (1);
  117.         }
  118.     return (*s2);
  119. }
  120.